<template>
  <div>
    <div v-if="Object.keys(list).length">
      <div class="collection">
        <ul>
          <li>
            <van-button block @click="favorite">
              <div v-if="flag"><van-icon name="star-o" /> 收藏</div>
              <div v-else><van-icon name="star" color="#fa5741" /> 已收藏</div>
            </van-button>
          </li>
          <li><van-button type="default" block>在线咨询</van-button></li>
          <li><van-button type="primary" block>电话预约</van-button></li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { addFavorite, delFavorite, viewFavorites } from '@/api/article'

export default {
  name: 'BottomBar',
  props: {
    list: {
      type: Object,
      default: () => ({})
    }
  },
  async created () {
    const res = await viewFavorites()
    res.body.forEach(item => {
      if (item.houseCode === this.$route.query.id) {
        this.flag = false
      }
    })
  },
  data () {
    return {
      flag: true
    }
  },
  methods: {
    favorite () {
      if (this.flag) {
        addFavorite(this.$route.query.id)
        this.flag = false
      } else {
        delFavorite(this.$route.query.id)
        this.flag = true
      }
    }
  }
}
</script>

<style lang="less" scoped>
.collection {
  z-index: 9999;
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  ul {
    display: flex;
    justify-content: space-between;
    li {
      width: 100%;
      color: #e1e1e1;
    }
  }
}
</style>
